import tkinter as tk;
import tkinter.messagebox;
from tkinter import ttk;
import keyboard,time,threading;
import pyautogui,sys,ctypes;
import logging

logging.basicConfig(level=logging.DEBUG,#控制台打印的日志级别
                    filename='new.log',
                    filemode='a',##模式，有w和a，w就是写模式，每次都会重新写日志，覆盖之前的日志
                    #a是追加模式，默认如果不写的话，就是追加模式
                    format=
                    '%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'
                    #日志格式
                    )

pyautogui.PAUSE = 0;
def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin();
    except:
        return False;
if is_admin():
    pass;
else:
    ctypes.windll.shell32.ShellExecuteW(None,"runas", sys.executable, __file__, None, 1);
    sys.exit();
value = 0;
def val(number):
    global value;
    value = number;
def err_show(message,title="错误"):
    tkinter.messagebox.showerror(title,message);
def start_():
    while keyboard.is_pressed('ctrl+t') == False:
        if combo_selected.get() == "点击左键":
            pyautogui.click();
            time.sleep(sleep);
        if combo_selected.get() == "点击右键":                                                                                  
            pyautogui.rightClick();
            time.sleep(sleep);
def start():
    global sleep;
    while True:
        while keyboard.is_pressed('ctrl+k')==False:
            pass;
        sleep = 1/inpu;
        start_();
def get():
    global inpu;
    global entered;
    try:
        inpu=int(entered.get());
    except:
        err_show("你输入的数值不符合要求，请重新输入");
        return None;
    if combo_selected.get() != "点击左键" and combo_selected.get() != "点击右键":
        err_show("你输入的数值不符合要求，请重新输入");
        return None;    
    if inpu <= 1000 == False or inpu >=1 == False:
        err_show("你输入的数值不符合要求，请重新输入");
    else:
        massage = "你填写的数："+str(inpu)+"\n你选择点击的键："+combo_selected.get()[2:3]+"\n按下 contral+k 开始\n按下 contral+t 停止";
        lb_2 = tk.Label(window,text=massage,width=32,height=4,fg="black");
        lb_2.pack();
        thread = threading.Thread(target=start);
        thread.start();
window = tk.Tk();
window.title("连点器");
window.geometry("230x190");
lb = tk.Label(window,text="每秒点击次数(在1-1000内)",width=20,height=1,fg="black");
form = ttk.Treeview(window)  
form["columns"] =("a","b")
form.column("a", width=100)
form.column("b", width=100)
form.insert("", 0, text="line1", values=("卡恩", "18", "180", "65"))#这一行

combo_selected = tkinter.StringVar()
combo = ttk.Combobox(window, textvariable=combo_selected)
combo["value"] = ("点击左键","点击右键") 

entered = tkinter.StringVar()
text = tk.Entry(window,width=4,textvariable=entered);




bt = tk.Button(text="输入好了",width=7,command=get,fg="black");
lb_3 = tk.Label(window,text="鼠标连点器V2.0.0   2023.10.13",width=24,height=2,fg="black");
logging.debug('11111')
 
lb.grid()
lb.pack();
text.pack();
combo.pack();
bt.pack();
lb_3.pack();
tk.mainloop();
